function intersection(nums1, nums2) {
    return nums2.filter(item => nums1.indexOf(item) != -1)
}

function unionsection(nums1, nums2) {
    return nums1.concat(nums2.filter(item => nums1.indexOf(item) === -1))
}

var nums1 = [1, 2, 3], nums2 = [2, 3, 4, 5];
// let res = intersection(nums1, nums2);
// console.log(res);
// let res = unionsection(nums1, nums2);
// console.log(res);

// es6
var intersection = nums1.filter(item => new Set(nums2).has(item));
console.log(intersection);
var unionsection = Array.from(new Set([...nums1, ...nums2]));
console.log(unionsection);
